﻿<template>
	<div class="uploadLog-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="queryParams" ref="queryForm" labelWidth="90">
				<el-row>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
						<el-form-item label="关键字">
							<el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="选择项目">
							<el-select clearable="" filterable="" v-model="queryParams.projectId" placeholder="请选择项目ID">
								<el-option v-for="(item, index) in projectProjectIdDropdownList" :key="index" :value="item.value" :label="item.label" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="客户端设备号">
							<el-input v-model="queryParams.clientSn" clearable="" placeholder="请输入客户端设备号" />
						</el-form-item>
					</el-col>
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="人员编号">
							<el-input v-model="queryParams.employeeId" clearable="" placeholder="请输入人员编号" />
						</el-form-item>
					</el-col> -->
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="抓拍时间">
							<el-input v-model="queryParams.cap_time" clearable="" placeholder="请输入抓拍时间" />
						</el-form-item>
					</el-col> -->
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="人员姓名">
							<el-input v-model="queryParams.empName" clearable="" placeholder="请输入人员姓名" />
						</el-form-item>
					</el-col> -->
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI"> </el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI"> </el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI"> </el-col>
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="错误信息">
							<el-input v-model="queryParams.errorMsg" clearable="" placeholder="请输入错误信息" />
						</el-form-item>
					</el-col> -->
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="审核状态">
							<el-select clearable="" v-model="queryParams.auditingStatus" placeholder="请选择审核状态">
								<el-option v-for="(item, index) in dl('AuditingStatusType')" :key="index" :value="item.value" :label="`${item.name} (${item.code}) [${item.value}] `" />
							</el-select>
						</el-form-item>
					</el-col>

					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="上传状态">
							<el-select clearable="" v-model="queryParams.isUpload" placeholder="请选上传状态">
								<el-option v-for="(item, index) in dl('TrueOrFalse')" :key="index" :value="item.value" :label="`${item.name} (${item.code}) [${item.value}] `" />
							</el-select>
						</el-form-item>
					</el-col> -->
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
						<el-form-item>
							<el-button-group style="display: flex; align-items: center">
								<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'uploadLog:page'"> 查询 </el-button>
								<el-button icon="ele-Refresh" @click="() => (queryParams = {})"> 重置 </el-button>
								<el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left: 5px"> 高级查询 </el-button>
								<el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left: 5px"> 隐藏 </el-button>
								<el-button type="primary" style="margin-left: 5px" icon="ele-Plus" @click="openAddUploadLog" v-auth="'uploadLog:add'"> 新增 </el-button>
							</el-button-group>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" @sort-change="sortChange" border="">
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="projectId" label="项目名称" show-overflow-tooltip="">
					<template #default="scope">
						<span>{{ scope.row.projectIdName }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="clientSn" label="客户端设备号" show-overflow-tooltip="" align="center" width="160" />
				<!-- <el-table-column prop="employeeId" label="人员编号" show-overflow-tooltip="" /> -->
				<el-table-column prop="cap_time" label="抓拍时间" show-overflow-tooltip="" align="center" width="160" :formatter="DateFormatter" />
				<el-table-column prop="empName" label="人员姓名" show-overflow-tooltip="" align="center" width="80" />
				<el-table-column prop="imageBase64" label="通行图像" show-overflow-tooltip="" align="center" width="70">
					<template #default="scope">
						<div>
							<el-image
								style="width: 42px; height: 42px"
								:src="'data:image/jpeg;base64,' + scope.row.imageBase64"
								:zoom-rate="1.2"
								:max-scale="7"
								:min-scale="0.2"
								:preview-src-list="['data:image/jpeg;base64,' + scope.row.imageBase64]"
								:initial-index="0"
								:preview-teleported="true"
								fit="cover"
							/></div
					></template>
				</el-table-column>
				<el-table-column prop="isMobile" label="移动考勤" show-overflow-tooltip="" align="center" width="80">
					<template #default="scope">
						<el-tag v-if="scope.row.isMobile" type="success" style="background-color: green; color: white"> 是 </el-tag>
						<div type="danger" v-else></div>
					</template>
				</el-table-column>
				<el-table-column prop="isUpload" label="是否已上传" show-overflow-tooltip="" align="center" width="80">
					<template #default="scope">
						<el-tag v-if="scope.row.isUpload" type="success" style="background-color: green; color: white"> 是 </el-tag>
						<div type="danger" v-else></div>
					</template>
				</el-table-column>
				<el-table-column prop="isUploadErr" label="上传错误" show-overflow-tooltip="" align="center" width="80">
					<template #default="scope">
						<el-tag v-if="scope.row.isUploadErr" type="success" style="background-color: green; color: white"> 是 </el-tag>
						<div type="danger" v-else></div>
					</template>
				</el-table-column>
				<el-table-column prop="errorMsg" label="错误信息" show-overflow-tooltip="" />
				<el-table-column prop="auditingStatus" label="审核状态" show-overflow-tooltip="" align="center" width="80">
					<template #default="scope">
						<!-- <el-tag :type="dv('AuditingStatusType', scope.row.auditingStatus)?.tagType"> {{ dv('AuditingStatusType', scope.row.auditingStatus)?.name }}</el-tag> -->
						<el-tag v-if="scope.row.auditingStatus" type="success" style="background-color: green; color: white"> 是 </el-tag>
						<div type="danger" v-else></div>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('uploadLog:update') || auth('uploadLog:delete')">
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditUploadLog(scope.row)" v-auth="'uploadLog:update'"> 编辑 </el-button>
						<el-button icon="ele-Delete" size="small" text="" type="primary" @click="delUploadLog(scope.row)" v-auth="'uploadLog:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				size="small"
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
			/>
			<printDialog ref="printDialogRef" :title="printUploadLogTitle" @reloadTable="handleQuery" />
			<editDialog ref="editDialogRef" :title="editUploadLogTitle" @reloadTable="handleQuery" />
		</el-card>
	</div>
</template>

<script lang="ts" setup="" name="uploadLog">
import { ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { auth } from '/@/utils/authFunction';

import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
import { formatDate } from '/@/utils/formatTime';

import printDialog from '/@/views/system/print/component/hiprint/preview.vue';
import editDialog from '/@/views/main/uploadLog/component/editDialog.vue';
import { pageUploadLog, deleteUploadLog } from '/@/api/main/uploadLog';
import { getProjectProjectIdDropdown } from '/@/api/main/uploadLog';
import { getAPI } from '/@/utils/axios-utils';
import { SysEnumApi } from '/@/api-services/api';
import commonFunction from '/@/utils/commonFunction';

const showAdvanceQueryUI = ref(false);
const printDialogRef = ref();
const editDialogRef = ref();
const loading = ref(false);
const tableData = ref<any>([]);
const queryParams = ref<any>({});
const tableParams = ref({
	page: 1,
	pageSize: 10,
	total: 0,
});

const printUploadLogTitle = ref('');
const editUploadLogTitle = ref('');

// 改变高级查询的控件显示状态
const changeAdvanceQueryUI = () => {
	showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
};

const DateFormatter = (row: any, column: any, cellValue: any, index: number) => {
	const date = new Date(cellValue);
	const formattedDate =
		date.getFullYear() +
		'-' +
		String(date.getMonth() + 1).padStart(2, '0') +
		'-' +
		String(date.getDate()).padStart(2, '0') +
		' ' +
		String(date.getHours()).padStart(2, '0') +
		':' +
		String(date.getMinutes()).padStart(2, '0') +
		':' +
		String(date.getSeconds()).padStart(2, '0');
	return formattedDate;
};

// 查询操作
const handleQuery = async () => {
	loading.value = true;
	var res = await pageUploadLog(Object.assign(queryParams.value, tableParams.value));
	tableData.value = res.data.result?.items ?? [];
	tableParams.value.total = res.data.result?.total;
	loading.value = false;
};

// 列排序
const sortChange = async (column: any) => {
	queryParams.value.field = column.prop;
	queryParams.value.order = column.order;
	await handleQuery();
};

// 打开新增页面
const openAddUploadLog = () => {
	editUploadLogTitle.value = '添加通行记录';
	editDialogRef.value.openDialog({});
};

// 打开打印页面
const openPrintUploadLog = async (row: any) => {
	printUploadLogTitle.value = '打印通行记录';
};

// 打开编辑页面
const openEditUploadLog = (row: any) => {
	editUploadLogTitle.value = '编辑通行记录';
	editDialogRef.value.openDialog(row);
};

// 删除
const delUploadLog = (row: any) => {
	ElMessageBox.confirm(`确定要删除吗?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			await deleteUploadLog(row);
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};

// 改变页面容量
const handleSizeChange = (val: number) => {
	tableParams.value.pageSize = val;
	handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
	tableParams.value.page = val;
	handleQuery();
};

const projectProjectIdDropdownList = ref<any>([]);
const getProjectProjectIdDropdownList = async () => {
	let list = await getProjectProjectIdDropdown();
	projectProjectIdDropdownList.value = list.data.result ?? [];
};
getProjectProjectIdDropdownList();

handleQuery();
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
